<?php
class App_Module_Admin_Component_Groups_Tpl_List extends App_Module_Admin_Tpl_List
{
	protected $_showCells = array('id', 'title', 'owner', 'icons');
	protected $_emptyListMessage = 'NO_GROUPS';
	
    public function GetList()
    {
        $icons = array(
        	array(
        	'add' => array(
        					'title' => 'ADD',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=groups&action=add')
        					),
        	)
        );
        
        $mapper = Mozg_Mapper::Get('Groups');
        $groups = Mozg::User()->GetAvailableGroups();
        $objects = array();
        foreach ($groups as $id)
        {
        	$group = $mapper->GetOne(array('id' => $id));
        	if (!$group) continue;
        	
        	$objects[] = $group;
        }
        
        $content = $this->CreateList($objects);
        
        return $this->GetTpl('Base')->LoadTemplate(Mozg_Lang::_('GROUPS'), $content, $icons);
    }
    
    protected function GetHeaderId()
    {
    	return '#';
    }
    
    protected function GetHeaderTitle()
    {
    	return Mozg_Lang::_('GROUP');
    }
    
    protected function GetHeaderOwner()
    {
    	return Mozg_Lang::_('GROUP_OWNER');
    }

	protected function GetCellId($obj)
	{
		return $obj->GetId();
	}
    
	protected function GetCellTitle($obj)
	{
		$this->obj = $obj;
		return $this->render('groups/list/_title.phtml');
	}
	
	protected function GetCellOwner($obj)
	{
		return Mozg_Mapper::Get('Groups')->GetOne(array('id' => $obj->GetParentId()))->GetTitle();
	}
	
	protected function GetCellIcons($obj)
	{
        $icons = array(
        	'edit' => array(
        					'title' => 'EDIT',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=groups&action=add&id=' .$obj->GetId())
        					),

        	'delete' => array(
        					'title' => 'DELETE_GROUP?',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=groups&action=del&id=' .$obj->GetId())
        					),

        );
		return $this->GetTpl('Icon')->GetIconSet($icons, 'list');
	}
}